home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / drgnsmth.cpt / Dragonsmith 1.1 / Base files / Dragon.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-10  |  9.6 KB  |  253 lines

  1. /*
  2.     Dragon.h
  3.     
  4.     Interface to Dragon.c
  5. */
  6.  
  7. #pragma once
  8.  
  9. #include    "AppleEventQueue.h"
  10. #include    "Preferences.h"
  11. #include    "FileUtils.h"
  12.  
  13. #define    prefDragonPrefs    0                // This class's preferences number (see Preferences.c)
  14.  
  15. // Structure of the 'DrPr' 128 resource
  16. typedef struct {
  17.     short    miscFlags;
  18.     short    reserved;
  19.     long        sleep[4];
  20.     short    depthLim;
  21. } DragonPrefsRec;
  22.  
  23. // Masks for use with miscFlags
  24. enum {
  25.     maskFilesOnly = 1,
  26.     maskResolveAliases = 2,
  27.     maskFollowAliasChain = 4,
  28.     maskAutoQuit = 8
  29. };
  30.  
  31. // Possible values for runState ╤ are we in the foreground or background, and are we idle or are we busy (i.e., processing docs)?
  32. enum {
  33.     kFGIdle,        // binary ╔0000
  34.     kBGIdle,        // binary ╔0001
  35.     kFGBusy,    // binary ╔0010
  36.     kBGBusy        // binary ╔0011
  37. };
  38.  
  39. // Masks for use with runState
  40. //    If we're in the background, runState & maskInBG != FALSE
  41. //    If we're busy, runState & maskBusy != FALSE
  42. enum {
  43.     maskInBG = 1,    // binary ╔0001
  44.     maskBusy = 2        // binary ╔0010
  45. };
  46.  
  47. class Dragon: indirect {
  48.  
  49.     protected:
  50.         FSSpec            *curDocFSS;        // Pointer to an FSSpec to the current file or folder (or volume)
  51.         PBRecUnion        *curDocPB;        // Pointer to a multi-purpose param block containing info about the current doc
  52.         short            dirDepthLimit;        // Recursively open folders and volumes to this level (0 == don't open
  53.                                         //    them, -1 == go down one level, etc.)
  54.         short            curDirDepth;        // Where are we now? ╤ 0 == at top level, -1 == down one, etc.
  55.         Boolean            filesOnly;            // Do we ignore folders and volumes that appear at the lowest level?
  56.                                         //     (i.e., when curDirDepth == dirDepthLimit)
  57.         Boolean            resolveAliases;    // Resolve any aliases we end up with after opening folders and disks?
  58.         Boolean            followAliasChain;    // Resolve them all the way, or just one step of the way?
  59.         Boolean            useCustomFilter;    // Should we use the CustomFilterOne method to check each FSSpec?
  60.         TypeListHndl        acceptableTypes;    // List (derived from our 'FREF' resources) of all the types of things we
  61.                                         //    can digest
  62.  
  63.         OSType            prefsFileType;        // Our prefs file's type
  64.         Preferences        *preferences;        // Preferences-managing object
  65.         DragonPrefsRec    **dragonPrefs;    // Handle to the resource containing preferences used by Dragon
  66.                                         //    (provided so that subclasses can let the user change them)
  67.         short            appResFork;        // The application file's resource fork refNum
  68.         FSSpec            appFile;            // An FSSpec that identifies the dragon's application file
  69.         
  70.         OSType            signature;        // The dragon application's signature
  71.         short            runState;            // What state are we in ╤ processing docs?  in the background?
  72.         long                sleepTime;        // Maximum number of ticks to yield to WaitNextEvent
  73.         long                sleepValue[4];        // One sleepTime value for each of the 4 states (see the enum above)
  74.         CursHandle        busyCursor;        // The cursor we show when we're busy
  75.         RgnHandle        cursorRgn;        // For WaitNextEvent
  76.         Boolean            running;            // Are we running?
  77.         Boolean            abortProcessing;    // Should we stop processing docs?
  78.         Boolean            autoQuit;            // Should we automatically quit after the first 'oapp' or 'odoc'?
  79.         Boolean            menusInstalled;    // Do we have working menus?
  80.         
  81.         AppleEventQueue    *aeQueue;        // Queue object used to manage suspended Apple events
  82.         short            numAEsPending;    // Number of Apple events that we've received but not yet processed
  83.         
  84.         MenuHandle        appleMenu;
  85.         MenuHandle        fileMenu;
  86.         MenuHandle        editMenu;
  87.         
  88.     public:
  89.                         Dragon (void);        // Constructor
  90.         virtual void        Start (void);
  91.         virtual void        Run (void);
  92.         virtual OSErr        DoOapp (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  93.         virtual OSErr        DoOdoc (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  94.         virtual OSErr        DoPdoc (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  95.         virtual OSErr        DoQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  96.         virtual Boolean    WaitIdle (EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn);
  97.         virtual void        StopRunning (OSErr err);
  98.         virtual void        Finish (void);
  99.  
  100.     protected:
  101.         virtual void        BeginProcessing (void);
  102.         virtual void        EndProcessing (void);
  103.         virtual void        StopProcessing (OSErr err);
  104.  
  105.         virtual Boolean    CanProcessDoc (void);
  106.         virtual Boolean    CustomFilterDoc (void);
  107.         
  108.         virtual OSErr        ProcessDroppings (AEDescList *docList);
  109.         virtual void        ProcessDoc (void);
  110.         virtual void        ProcessFile (void);
  111.         virtual void        ProcessDirectory (void);
  112.         virtual void        ProcessDocsInDirectory (short vRefNum, long dirID);
  113.         virtual void        ProcessOwnedFile (void);
  114.         virtual void        SaveDocInfo (Boolean refreshFinder);
  115.         
  116.         virtual void        DoBusy (void);
  117.         virtual void        ShowProgress (void);
  118.         virtual void        AdjustMenusBusy (void);
  119.         virtual void        AdjustMenusIdle (void);
  120.         virtual void        CursorBusy (void);
  121.         virtual void        CursorIdle (void);
  122.         
  123.         virtual OSErr        SuspendAEvent (AppleEvent *event, AppleEvent *reply, AEHandlerFunc *handler, long refcon);
  124.         virtual void        ResumeAEvent (void);
  125.         virtual void        FlushAEventQueue (void);
  126.         
  127.         virtual void        DoEvent (EventRecord *event);
  128.         virtual void        DoMouseDown (EventRecord *theEvent);
  129.         virtual void        DoMouseUp (EventRecord *theEvent);
  130.         virtual void        DoKeyDown (EventRecord *theEvent);
  131.         virtual void        DoActivate (EventRecord *theEvent);
  132.         virtual void        DoDeactivate (EventRecord *theEvent);
  133.         virtual void        DoUpdateEvent (EventRecord *theEvent);
  134.         virtual void        DoDiskInsert (EventRecord *theEvent);
  135.         virtual void        DoOSEvent (EventRecord *theEvent);
  136.         virtual void        DoHighLevelEvent (EventRecord *theEvent);
  137.         virtual void        DoOtherHLEvent (EventRecord *theEvent);
  138.         virtual void        DoIdle (void);
  139.         virtual void        DoSuspend (void);
  140.         virtual void        DoResume (void);
  141.         
  142.         virtual void        DoMenu (long menuItemCode);
  143.         virtual void        DoAppleMenu (short itemNum);
  144.         virtual void        DoAbout (void);
  145.         virtual void        DoFileMenu (short itemNum);
  146.         virtual void        DoEditMenu (short itemNum);
  147.         
  148.         virtual void        InitMac (void);
  149.         virtual void        InitMilieu (void);
  150.         virtual void        InitMem (void);
  151.         virtual void        InitPrefs (void);
  152.         virtual Preferences *MakePrefsObject (void);
  153.         virtual Boolean    MakePrefsFile (FSSpec *fss);
  154.         virtual Boolean    FindPrefsFile (FSSpec *fss);
  155.         virtual Boolean    IsPrefsFile (FSSpec *fss);
  156.         virtual void        ReadPrefs (void);
  157.         virtual void        SetUpMenus (void);
  158.         virtual void        CallMoreMasters (void);
  159.         virtual void        InitAppleEvents (void);
  160.         virtual AppleEventQueue   *MakeAEQObject (void);
  161.         virtual Boolean    InteractWithUser (long timeOut);
  162.         virtual void        Abort (short errNum);
  163.         virtual void        Error (short errNum);
  164.         
  165. };
  166.  
  167. // Now we declare some macros for convenience' sake, so we can write
  168. //    curFileType = 'TEXT';
  169. // instead of
  170. //    curDocPB->cinfo.hFileInfo.ioFlFndrInfo.fdType = 'TEXT';
  171.  
  172. // These macros are valid for files and directories ╤
  173.     #define    curDocVRefNum        curDocFSS->vRefNum
  174.     #define    curDocParID            curDocFSS->parID
  175.     // This would also work:            curDocPB->c.hFileInfo.ioFlParID [or .dirInfo.ioDrParID, same thing]
  176.     #define    curDocName            curDocFSS->name                    // This is a pointer to a Pascal string, remember
  177.     #define    curDocCreated        curDocPB->c.hFileInfo.ioFlCrDat
  178.     #define    curDocModified        curDocPB->c.hFileInfo.ioFlMdDat
  179. // These macros can't be assigned to (of course) ╤
  180.     #define    curDocIsFile            !(curDocPB->c.hFileInfo.ioFlAttrib & ioDirMask)
  181.     #define    curDocIsDirectory        (curDocPB->c.hFileInfo.ioFlAttrib & ioDirMask)
  182.     #define    curDocIsVolume        (curDocFSS->parID == fsRtParID)
  183.     
  184. // These macros are valid only for files ╤
  185.     #define    curFileType            curDocPB->c.hFileInfo.ioFlFndrInfo.fdType
  186.     #define    curFileCreator            curDocPB->c.hFileInfo.ioFlFndrInfo.fdCreator
  187.     #define    curFileDataForkSize    curDocPB->c.hFileInfo.ioFlLgLen
  188.     #define    curFileResForkSize        curDocPB->c.hFileInfo.ioFlRLgLen
  189.     #define    curFileFlags            curDocPB->c.hFileInfo.ioFlFndrInfo.fdFlags
  190.     
  191. extern Dragon        *gDragon;
  192.  
  193. // ----------------        Error codes            ----------------
  194.  
  195.     enum {
  196.         eNormalQuit = noErr,            // Normal quitting (user chose Quit or autoQuit == TRUE) is not an error
  197.         eNoAppleEvents = 1001,
  198.         eCouldntInstallAppleEvents,
  199.         eInsufficientSystem = 1003,        // The current System does not have all the features this program needs
  200.         eInitializationFailed,            // Initialization failed for some miscellaneous reason
  201.         ePreferenceNotFound,            // We couldn't read a needed preference resource
  202.         eForcedQuit                    // We were forced to quit (i.e., we received a Quit event while processing)
  203.     };
  204.  
  205.     #define    eLastDragonError    eForcedQuit
  206.         
  207. // ----------------        Resource constants    ----------------
  208.  
  209.     #define    rErrorAlert        129
  210.     #define    kPrefsFileType    'pref'
  211.     #define    rPrefsFileName    128        // ID of the 'STR ' resource containing the name of our prefs file
  212.     #define    kGstCheckType    'GChk'
  213.     #define    rGstChecklist        128
  214.     
  215. // ----------------        Menu constants        ----------------
  216. enum {
  217.     mApple = 128,
  218.     mFile,
  219.     mEdit
  220. };
  221.  
  222. enum {            // Apple menu
  223.     iAbout = 1,
  224.     iLine1
  225. };
  226.  
  227.  
  228. // ----------------        Misc. constants        ----------------
  229. #define    kWatchCursor        4
  230.  
  231. // ----------------        Function prototypes    ----------------
  232.  
  233.     void main (void);
  234.     pascal OSErr HandleOapp (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  235.     pascal OSErr HandleOdoc (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  236.     pascal OSErr HandlePdoc (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  237.     pascal OSErr HandleQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  238.     pascal OSErr ReturnEventNotHandled (AppleEvent *theAppleEvent, AppleEvent *theReply, long refcon);
  239.     pascal Boolean CallWaitIdle (EventRecord *theEvent, long *sleep, RgnHandle *mouseRgn);
  240.  
  241.     Dragon *CreateGDragon (void);        // This function is NOT defined in Dragon.c ╤ you must define it elsewhere
  242.                                     //    so that it returns a new dragon of your subclass (not of Dragon!)
  243.  
  244. // Same data as a regular EventRecord, redone for High-Level events
  245. typedef struct {
  246.     short    what;
  247.     long        eventClass;
  248.     long        when;
  249.     long        eventID;
  250.     short    modifiers;
  251. } HLEventRecord, *HLEventPtr;
  252.  
  253.